/**
 * 角色 
 * author:noodles 
 */
package com.gamebase.role
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;
	import flash.geom.Rectangle;

	public class SubRole extends Role
	{
		public var roleMode:Avatar;
		
		public function SubRole()
		{
			super();
			roleMode = new Avatar();
			roleMode.addEventListener("avatarLoaded",modeInitalize);
			this.addChild(roleMode);
			this.mouseChildren = false;
		}
		
		private function modeInitalize(evt:Event):void
		{
			resetFront(
			new Rectangle(0,0,roleMode.width,roleMode.height),
			new Point(- roleMode.width/2 , - roleMode.realBottom)
			)
		}
		
		/**更改角色身体部位
		 *  @param changePartList:结构为[part:String,partURL:String]，part值为："all","head","body","leg","feet"
		 * */
		public function changPart(changePartList:Array):void
		{
			if(this.parent == null)
			{
				trace("换装失败，请先将角色添加到显示列表再换装");
				return;
			}
			roleMode.changBodyPart(changePartList);
		}
		
		/**
		 * 开始移动
		 * @parma movePath:移动路径 
		 * @parma cb：移动到目的地后要执行的函数
		 * */
		public function beginMove(movePath:Array,cb:Function=null):void
		{
			roleMode.beginMove(movePath,cb);
		}
		
		//是否包含于角色的非空像素
		public function containPoint(_x:Number,_y:Number):Boolean
		{
			return roleMode.containPoint(_x,_y);
		}
				
		public function destroy():void
		{
			roleMode.removeEventListener("avatarLoaded",modeInitalize);
			roleMode.destroy();
		}
	}
}